package com.dashu.device.controller;

import com.dashu.base.enums.device.DeviceType;
import com.dashu.device.result.ResultBean;
import com.dashu.device.service.CQ.CQInsideExternalService;
import com.dashu.device.service.HF.HFInsideExternalService;
import com.dashu.device.service.JL.JLInsideExternalService;
import com.dashu.device.vo.RestartReqVO;
import com.dashu.base.vo.DevicePicAddVO;
import com.dashu.base.vo.DevicePicDelReqVO;
import com.dashu.base.vo.DevicePicUpdReqVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.UnsupportedEncodingException;


/**
 * @Author xys
 * @Date 2020/11/17 15:21
 */

@RequestMapping("dashu/device")
@RestController
@Slf4j
@Api(value = "dashu/device", tags = {"设备模块"}, description = "后台")
public class DeviceController {
    @Autowired
    private CQInsideExternalService cqInsideExternalService;
    @Autowired
    private JLInsideExternalService jlInsideExternalService;
    @Autowired
    private HFInsideExternalService hfInsideExternalService;

    @PostMapping("/restart")
    @ApiOperation(value = "设备重启", notes = "设备后台")
    public ResultBean restart(@RequestBody RestartReqVO req) {
        if (req != null) {
            cqInsideExternalService.restart(req);
        }
        return new ResultBean<>(1, "设备重启", true);
    }

    @PostMapping("/establishUser")
    @ApiOperation(value = "设备添加图片", notes = "设备后台")
    public ResultBean establishUser(@RequestBody DevicePicAddVO req) throws Exception {
        if (req != null) {
            if (req.getDeviceType().equals(DeviceType.NEW_CONTROL)) {
                cqInsideExternalService.addUser(req);
            } else if (req.getDeviceType().equals(DeviceType.JL_CONTROL)) {
                jlInsideExternalService.addUser(req);
            }else if (req.getDeviceType().equals(DeviceType.HF_CONTROL)) {
                hfInsideExternalService.addUser(req);
            }
        }
        return new ResultBean<>(1, "设备添加图片", true);
    }

    @PostMapping("/delUser")
    @ApiOperation(value = "设备删除图片", notes = "设备后台")
    public ResultBean delUser(@RequestBody DevicePicDelReqVO req) throws UnsupportedEncodingException {
        if (req != null) {
            if (req.getDeviceType().equals(DeviceType.NEW_CONTROL)) {
                cqInsideExternalService.delPic(req);
            } else if (req.getDeviceType().equals(DeviceType.JL_CONTROL)) {
                jlInsideExternalService.delPic(req);
            } else if (req.getDeviceType().equals(DeviceType.HF_CONTROL)) {
                hfInsideExternalService.delPic(req);
            }
        }
        return new ResultBean<>(1, "设备删除图片", true);
    }

    @PostMapping("/updUser")
    @ApiOperation(value = "设备修改图片", notes = "设备后台")
    public ResultBean updUser(@RequestBody DevicePicUpdReqVO req) throws Exception {
        if (req != null) {
            if (req.getDeviceType().equals(DeviceType.NEW_CONTROL)) {
                cqInsideExternalService.updPic(req);
            } else if (req.getDeviceType().equals(DeviceType.JL_CONTROL)) {
                jlInsideExternalService.updPic(req);
            }else if (req.getDeviceType().equals(DeviceType.HF_CONTROL)) {
                hfInsideExternalService.updPic(req);
            }
        }
        return new ResultBean<>(1, "设备修改图片", true);
    }
}
